//
//  PlayDetailController.m
//  RentTable
//
//  Created by mac on 2024/11/30.
//

#import "PlayDetailController.h"

@interface PlayDetailController ()

@property (nonatomic, strong) UIScrollView *contentScollView;

@end

@implementation PlayDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUI];
}

- (void)setUI {
    
    CGFloat contentHeight = 1190 * scaleH;
    self.contentScollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, spDeviceWidth, spDeviceHeight - 64)];
    self.contentScollView.contentSize = CGSizeMake(spDeviceWidth, contentHeight);
    self.contentScollView.showsHorizontalScrollIndicator = NO;
    self.contentScollView.showsVerticalScrollIndicator = NO;
    self.contentScollView.contentInset = UIEdgeInsetsZero;
    self.contentScollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    [self.view addSubview:self.contentScollView];
    
    [self loadBackArrow];
    [self loadTitle:self.playTitle];
    
    UIImageView *playImageView = [UIImageView new];
    playImageView.image = [UIImage imageNamed:self.playImage];
    [self.contentScollView addSubview:playImageView];
    [playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(88 * scaleH);
        make.width.mas_equalTo(spDeviceWidth);
        make.height.mas_equalTo(200 * scaleH);
    }];
    
    UILabel *sumLabel = [[UILabel alloc] init];
    sumLabel.text = @"游戏规则";
    sumLabel.font = [UIFont pingFangSCMediumWithSize:17];
    sumLabel.textColor = myRGBHex(0x333333);
    [self.contentScollView addSubview:sumLabel];
    [sumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(21);
        make.top.equalTo(playImageView.mas_bottom).offset(20);
        make.height.mas_equalTo(22 * scaleH);
    }];
    


    NSString *text = @"开球\n首局比赛一般通过掷币决定开球权，以后每局由上局获胜者先开球。开球时，主球需放在开球区（D 区）线上或线内的任意位置，击打主球使其碰到红球即为开球成功.\n击球顺序\n开球后，每轮次的第一击以红球为活球，直至所有红球全部离台为止。击球者击打红球入袋后，可继续选择一个彩球击打，彩球入袋后放回置球点，然后再击打红球，如此红球与彩球交替落袋。红球全部离台后，台面上的彩球按分值从小到大，依次成为活球，当下一彩球进袋后（除特殊情况外），即留在桌外，不再取出，击球运动员再击打下一个彩球.\n得分计算\n将目标球击打入袋即可得分，分值根据球的颜色而定，红球 1 分，黄球 2 分，绿球 3 分，棕球 4 分，蓝球 5 分，粉球 6 分，黑球 7 分，一杆球之内每个入袋的活球的分值均记入击球运动员的得分记录.\n犯规及处罚\n常见的犯规行为包括球未停稳就击球、击球时杆头触击主球一次以上、击成空杆、主球击目标球后自落、击球时双脚离地、开球时主球未放入开球区、击成跳球、击球出界、主球首先撞击非活球、击球时球员的衣服身体球杆及佩戴物等触动台面上的球等。处罚方式一般是将罚分加在对手的分数记录上，不同的犯规行为罚分不同，如未按击球顺序击球、空杆、主球落袋等一般罚 4 分；使非活球入袋、主球首先击打到非活球等一般罚有关球的最高分值；而击红球入袋后，尚未指定球就开始击球、击进红球后，未报彩球又击打红球、不使用白球而使用其他任何一个球作主球等则罚 7 分.";
    
    CGFloat maxWidth = spDeviceWidth-32;
    CGRect boundingRect = [text boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX)
                                             options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                          attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14]}
                                             context:nil];

    CGFloat textHeight = ceil(boundingRect.size.height);
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(21, 342 * scaleH, spDeviceWidth-32, textHeight);
    label.numberOfLines = 0;
    [self.contentScollView addSubview:label];
    self.contentScollView.contentSize = CGSizeMake(spDeviceWidth, 360 + textHeight);
    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text];

    NSDictionary *attributes = @{
        NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14],
        NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]
    };

    [string addAttributes:attributes range:NSMakeRange(0, text.length)];

    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]} range:NSMakeRange(0, 2)];
    [string addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14]} range:NSMakeRange(2, 76)];
    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]} range:NSMakeRange(78, 5)];
    [string addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14]} range:NSMakeRange(83, 157)];
    [string addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1]} range:NSMakeRange(240, 5)];
    [string addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:14]} range:NSMakeRange(245, 372)];

    label.attributedText = string;
    label.textAlignment = NSTextAlignmentLeft;
    label.alpha = 1.0;

}


@end
